package com.book.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.book.pojo.Readers;
import com.book.mapper.ReadersDao;
import com.book.service.ReadersService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author fk
 * @since 2023-10-12 20:13:22
 */
@Service
public class ReadersServiceImpl extends ServiceImpl<ReadersDao, Readers> implements ReadersService {

    @Autowired
    private ReadersDao readersDao;
    @Autowired
    private RedisTemplate redisTemplate;


    @Override
    public Readers getByReaderId(Long readerId) {

        return readersDao.selectById(readerId);
    }

    @Override
    public void getupdate(Readers readers) {
        int num = readers.getMonthlyNum()+1;
        readers.setMonthlyNum(num);
        readersDao.updateById(readers);
    }


    @Override
    public Readers getByid(Long userId) {
        return readersDao.selectById(userId);
    }

    @Override
    public int updatepassword(Readers byid) {
        return readersDao.updateById(byid);
    }

    @Override
    public Readers getAll(Long userId) {
        QueryWrapper<Readers> qdw = new QueryWrapper<>();
        qdw.eq("id",userId);
        return readersDao.selectById(qdw);
    }

    @Override
    public void updateUser(Readers readers) {
        readersDao.updateById(readers);
    }

    @Override
    public void deleteReaders(Long userId) {
        readersDao.deleteById(userId);
    }


}
